﻿using Core.Log;

namespace Game.Trade {
    /// <summary>
    /// 交易系统
    /// </summary>
    public class TradeSystem {
        public static void ExecuteTrade(IBuyer buyer,ISeller seller,ISellable thing) {
            if (!CheckTrade(buyer, seller, thing)) {
                return;
            }
            seller.Sell(thing);
            buyer.Buy(thing);
            ADbg.LogF("[Trade] 交易成功");
        }

        /// <summary>
        /// 交互检查
        /// </summary>
        public static bool CheckTrade(IBuyer buyer,ISeller seller,ISellable thing) {
            //金钱检查
            if (buyer.Money < thing.Cost) {
                return false;
            }

            if (!CheckMutex()) {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 交易互斥
        /// </summary>
        public static bool CheckMutex() {
            return true;
        }
    }
}